package com.jingbian.cppccbackend.task;

import com.jingbian.cppccbackend.service.user.IActivitiesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@EnableScheduling
public class ActivityTask {
  @Autowired
  private IActivitiesService activitiesService;

  // 每10秒执行一次
  @Scheduled(cron = "0/10 * * * * ? ")
  public void testSchedule() {
    try {
      log.info("开始执行活动状态更新任务，线程ID: {}", Thread.currentThread().getId());
      activitiesService.updateTimeStatus();
      log.info("活动状态更新任务执行完成，线程ID: {}", Thread.currentThread().getId());
    } catch (Exception e) {
      log.error("活动状态更新任务执行失败，线程ID: {}, 错误信息: {}", Thread.currentThread().getId(), e.getMessage(), e);
    }
  }
}
